package com.itheima.dao;

import com.itheima.pojo.Address;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AddressDao {
    @Select("select * from t_address")
    List<Address> getAllAddress();

    @Select("select * from t_address where name like CONCAT('%',#{queryString},'%')")
    List<Address> findAddressByQueryString(String queryString);

    @Insert("insert into t_address (img,longitudeAnddimensionality,telephone,name,address) values(#{img},#{longitudeAnddimensionality},#{telephone},#{name},#{address})")
    void insertToAddress(Address address);

    @Delete("delete from t_address where id=#{id}")
    void deleteToAddress(Integer id);

    @Select("select count(*) from t_order_address where address_id=#{addressId}")
    Integer findByAddressId(Integer addressId);

    @Select("select * from t_address where id=#{addressId}")
    Address findByid(Integer addressId);

    @Update("update t_address set img=#{img},longitudeAnddimensionality=#{longitudeAnddimensionality},telephone=#{telephone},name=#{name},address=#{address} where id=#{id}")
    void update(Address address);

    @Select("select address from t_address")
    List<String> findAll();

    @Select("select id from t_address where address = #{address}")
    Integer findByAddress(String address);
}
